// EGC
// Laborator 6
//-------------------------------------------------

#include "camera.h"
#include "math.h"


// constructor
Camera::Camera()
{
	//initializare cu valorile standard OpenGL
	Position[2] = 	12;
	ForwardVector[2] =  -1.0;
	RightVector[0] = 1.0;
	UpVector[1] =  1.0;
}

void Camera::RotateX (GLfloat Angle)
{
}

void Camera::RotateY (GLfloat Angle)
{
}

void Camera::RotateZ (GLfloat Angle)
{
}

// rotire fata de centru, la o distanta generica 5
void Camera::RotateXCenter (GLfloat Angle)
{
}

// rotire fata de centru, la o distanta generica 5
void Camera::RotateYCenter (GLfloat Angle)
{
	float distance = 5;
	MoveForward(distance);
	RotateY(Angle);
	MoveBackward(distance);
}

// rotire fata de centru, la o distanta generica 5
void Camera::RotateZCenter (GLfloat Angle)
{
	float distance = 5;
	MoveForward(distance);
	RotateZ(Angle);
	MoveBackward(distance);
}

// plasare observator in scena
void Camera::Render( void )
{
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	// punctul catre care se uita camera
	float ViewPoint[3];
	for (int i = 0 ; i < 3 ; i++)
		ViewPoint[i] = Position[i] + ForwardVector[i];

	// stim vectorul UpVector, folosim LookAt
	gluLookAt(	Position[0],Position[1],Position[2],
		ViewPoint[0],ViewPoint[1],ViewPoint[2],
		UpVector[0],UpVector[1],UpVector[2]);
}

// miscari simple, pe toate axele

void Camera::MoveForward( GLfloat Distance )
{
	for (int i = 0 ; i < 3 ; i++)
		Position[i] += ForwardVector[i]*Distance;


}

void Camera::MoveBackward( GLfloat Distance )
{
	for (int i = 0 ; i < 3 ; i++)
		Position[i] -= ForwardVector[i]*Distance;
}

void Camera::MoveRight ( GLfloat Distance )
{
	for (int i = 0 ; i < 3 ; i++)
		Position[i] -= RightVector[i]*Distance;
}

void Camera::MoveLeft ( GLfloat Distance )
{
	for (int i = 0 ; i < 3 ; i++)
		Position[i] += RightVector[i]*Distance;
}

void Camera::MoveUpward( GLfloat Distance )
{
	for (int i = 0 ; i < 3 ; i++)
		Position[i] += UpVector[i]*Distance;
}

void Camera::MoveDownward( GLfloat Distance )
{
	for (int i = 0 ; i < 3 ; i++)
		Position[i] -= UpVector[i]*Distance;
}

// seteaza pozitie
void Camera::SetPosition(float x, float y, float z)
{
	Position[0] = x;
	Position[1] = y;
	Position[2] = z;
}

// seteaza forward vector
void Camera::SetForwardVector(float x, float y, float z)
{
	ForwardVector[0] = x;
	ForwardVector[1] = y;
	ForwardVector[2] = z;
}

// seteaza right vector
void Camera::SetRightVector(float x, float y, float z)
{
	RightVector[0] = x;
	RightVector[1] = y;
	RightVector[2] = z;
}

// seteaza up vector
void Camera::SetUpVector(float x, float y, float z)
{
	UpVector[0] = x;
	UpVector[1] = y;
	UpVector[2] = z;
}